package com.orangelife.mobile.parkingcard.adapter;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.curry.orangelife.mobile.R;
import com.curry.android.adapter.FatherAdapter;
/**
 * 缴费时长适配器
 * @author Administrator
 *
 */
public class GridViewLongTimeAdapter<T> extends FatherAdapter<T>{
	private Context context;
    private List<Map<String,Object>> list;
    public GridViewLongTimeAdapter(Context context,List<Map<String,Object>> list){
    	this.context = context;
		this.list = list;
    }
    
    private int clickTemp = -1;
    //标识选择的Item
    public void setSeclection(int position) {
      clickTemp = position;
    }
    
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_gv_buy_fresh, null);
			viewHolder = new ViewHolder();
			viewHolder.llLongTime = (LinearLayout) convertView
					.findViewById(R.id.llLongTime);
			viewHolder.tvLongTime = (TextView) convertView
					.findViewById(R.id.tvWeight);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		Map<String, Object> map = (Map<String, Object>) list.get(position);
		viewHolder.tvLongTime.setText(map.get("quantity").toString()+map.get("unit"));
		
		if (clickTemp == position) {
			viewHolder.tvLongTime.setBackgroundColor(Color.GRAY);
		    } else {
		    	viewHolder.tvLongTime.setBackgroundColor(Color.WHITE);
		    }
		return convertView;
	}

    class ViewHolder{
    	/**时长*/
    	TextView tvLongTime;
    	LinearLayout llLongTime;
    }

	@Override
	public BaseAdapter setList(List<T> list) {
		this.list = (List<Map<String,Object>>) list;
		return GridViewLongTimeAdapter.this;
	}
}
